<?php

class Application_Form_Adduser extends Zend_Form
{

    public function __construct()
    {
        $translate = new My_Action_Helper_Lang();
        
        $this->setName('form_user_registration');
        parent::__construct();

        $login = new Zend_Form_Element_Text('email');
        $login->setLabel($translate->_('Email'))
                ->setRequired(true)
                ->addValidator('NotEmpty')
                ->addValidator('Db_NoRecordExists', false, array(
                    'table' => 'users',
                    'field' => 'email'))
                ->addValidator('EmailAddress')
                ->addFilter('StringTrim')
                ->addFilter('StripTags');

        $password = new Zend_Form_Element_Password('password');
        $password->setLabel($translate->_('Password'))
                ->setRequired(true)
                ->addValidator('NotEmpty')
                ->addValidator('StringLength', true, array(8,20))
                ->addValidator('Alnum')
                ->addFilter('StringTrim')
                ->addFilter('StripTags');

        $password_confirm = new Zend_Form_Element_Password('password_confirm');
        $password_confirm->setLabel($translate->_('Enter password again'))
                ->setRequired(true)
                ->addValidator('NotEmpty')
                ->addValidator('Alnum')
                //Указываем префикс, путь и тип созданого валидатора
                ->addPrefixPath('myClass_Validator', 'myClass/Validator', 'validate')
                ->addValidator('Passwordconfirm')
                ->addFilter('StringTrim')
                ->addFilter('StripTags');

        $firstName = new Zend_Form_Element_Text('firstName');
        $firstName->setLabel($translate->_('Firstname'))
                ->setRequired(true)
                ->addValidator('NotEmpty')
                ->addValidator('Alpha', false, array('allowWhiteSpace' => true))
                ->addFilter('StringTrim')
                ->addFilter('StripTags');

        $lastName = new Zend_Form_Element_Text('lastName');
        $lastName->setLabel($translate->_('Lastname'))
                ->setRequired(true)
                ->addValidator('NotEmpty')
                ->addValidator('Alpha', false, array('allowWhiteSpace' => true))
                ->addFilter('StringTrim')
                ->addFilter('StripTags');

        $phone = new Zend_Form_Element_Text('phone');
        $phone->setLabel($translate->_('Phone'))
                ->addValidator('Digits')
                ->addFilter('StringTrim')
                ->addFilter('StripTags');

        $company = new Zend_Form_Element_Text('company');
        $company->setLabel($translate->_('Company'))
                ->setRequired(true)
                ->addValidator('NotEmpty')
                ->addValidator('Alnum', false, array('allowWhiteSpace' => true))
                ->addFilter('StringTrim')
                ->addFilter('StripTags');

        $country = new Zend_Form_Element_Text('country');
        $country->setLabel($translate->_('Country'))
                ->addValidator('Alnum', false, array('allowWhiteSpace' => true))
                ->addFilter('StringTrim')
                ->addFilter('StripTags');

        $city = new Zend_Form_Element_Text('city');
        $city->setLabel($translate->_('City'))
                ->addValidator('Alnum', false, array('allowWhiteSpace' => true))
                ->addFilter('StringTrim')
                ->addFilter('StripTags');

        $adress = new Zend_Form_Element_Text('adress');
        $adress->setLabel($translate->_('Address'))
                ->addValidator('Alnum', false, array('allowWhiteSpace' => true))
                ->addFilter('StringTrim')
                ->addFilter('StripTags');

        $site = new Zend_Form_Element_Text('site');
        $site->setLabel($translate->_('Site company'))
                ->addFilter('StringTrim')
                ->addFilter('StripTags');

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel($translate->_('Registration'))
               ->setAttrib('class', 'button');

        $this->addElements(array($login, $password, $password_confirm, 
            $firstName, $lastName, $phone, $company, $country, $city, $adress, $site, $submit));
    }
}

